import { withRouter } from 'react-router'
import { connect } from 'react-redux';
import { setToken } from '@/redux/action/index';
import Auth from '@/util/auth';
import { Row, Col, Button, Icon } from 'antd';
import less from './index.less';
import userImg from './demo.png';


class Top extends React.Component {
    state = {
        userName: '系统管理员'
    }

    outLogin = () => {
        console.log(this);
        // TO-DO 这里临时设置为清除后台登录状态成功后
        const { dispatch } = this.props;
        dispatch(setToken(''));
        Auth.removeLoginStatus();//设置cookie为登录状态
        this.props.history.push('/login')
    }


    render() {
        return (
            <div className={less.main_top}>
                <Row className={less.header_top}>
                    <Col span="24">
                        <Button className={less.userImg} shape="circle">
                            <img src={userImg} alt="" />
                        </Button>
                        <span>{this.state.userName}</span>
                        <a href="javascript:void(0)" onClick={this.outLogin}>
                            <Icon type="poweroff" />
                        </a>
                    </Col>
                </Row>
            </div>
        )
    }
}

export default withRouter(connect()(Top))